package de.haw.shc.JSONObjects;

import android.util.Log;
import de.haw.shc.Interfaces.DeviceProperty.iColorLight;
import de.haw.shc.Action.Actions;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: mizus
 * Date: 08.05.13
 * Time: 15:22
 * To change this template use File | Settings | File Templates.
 */
public class Light implements iColorLight {

    private String name,viewName, viewRaumName;
    private int fateTime = 0;
    private String action = Actions.LIGHTCONTROL;
    private String id, raum;

    int red, green, blue;

    private boolean colorLight;

    @Override
    public JSONObject createLightOn(){
        Map<String, Object> valMap = createValueMap(name + "on", 0,0,0, fateTime);
        JSONObject jsonObj = new JSONObject(valMap);
        Log.d("iLight.createOn", jsonObj.toString());
        return jsonObj;
    }

    @Override
    public JSONObject createLightOff(){
        Map<String, Object> valMap = createValueMap(name + "off", 255,255,255, fateTime);
        JSONObject jsonObj = new JSONObject(valMap);
        Log.d("iLight.createOFF", jsonObj.toString());
        return jsonObj;
    }

    @Override
    public JSONObject createColorLight(int red, int green, int blue, int fateTime) {
        Map<String, Object> valMap = createValueMap(name+"color", red, green, blue, fateTime);
        JSONObject jsonObj = new JSONObject(valMap);
        Log.d("iLight.createColorLight", jsonObj.toString());
        return jsonObj;
    }


    private Map<String, Object> createValueMap(String action, int red, int green, int blue, int fateTime){
        Map<String, String> valueMap = new HashMap<String, String>();
        valueMap.put("red", String.valueOf(red));
        valueMap.put("green", String.valueOf(green));
        valueMap.put("blue", String.valueOf(blue));
        valueMap.put("fadeTime", String.valueOf(fateTime));

        setColor(red,green,blue);

        Map<String, Object> aenderMap = new HashMap<String, Object>();
        aenderMap.put("values", new JSONObject(valueMap));
        aenderMap.put("Id", "StephanTimo");
        aenderMap.put("Version", null);
        aenderMap.put("action", action);
        Log.d("Werte Setzen", aenderMap.toString());
        return aenderMap;
    }

    @Override
    public JSONObject deactivate() {
        return this.createLightOff();  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public JSONObject activate(){
        return this.createLightOn();
    }

    @Override
    public String getDeviceControll() {
        return action;  //To change body of implemented methods use File | Settings | File Templates.
    }


    @Override
    public void setColor(int tred, int tgreen, int tblue) {
        red = tred;
        green = tgreen;
        blue = tblue;
    }

    @Override
    public void setRed(int red) {
        this.red = red;
    }

    @Override
    public int getRed() {
        return red;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void setGreen(int green) {
        this.green =  green;//To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public int getGreen() {
        return green;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void setBlue(int blue) {
       this.blue = blue; //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public int getBlue() {
        return blue;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public JSONObject createOffColorLight() {
        Map<String, Object> valMap = createValueMap(name+"color", 255, 255, 255, fateTime);
        JSONObject jsonObj = new JSONObject(valMap);
        Log.d("iLight.createColorLight", jsonObj.toString());
        return jsonObj;
    }

    @Override
    public void setFadetime(int fadetime) {
        fateTime = fadetime;
    }

    @Override
    public String getName() {
        return name;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String getID() {
        return id;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void setRaum(String aRaum) {
       raum  = aRaum;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String getRaum() {
        return raum;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void setName(String aName){
        name = aName;
    }

    @Override
    public void setID(String aID){
        id = aID;
    }

    @Override
    public boolean isColorPicker() {
        return colorLight;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void setColorable(boolean bool) {
        colorLight = bool;
    }

    @Override
    public void setViewName(String name) {
        viewName = name;    //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String getViewName() {
        return viewName;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void setViewRaumName(String name) {
        viewRaumName = name;//To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public String getViewRaumName() {
        return viewRaumName;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean isWindow() {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean isBlind() {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean isLight() {
        return true;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean isRadiator() {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public boolean isCurtain() {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }


    @Override
    public String toString(){
        return "Name: " + getViewName() + " Room: "+ getViewRaumName();
    }

}
